package com.nanhang;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.baomidou.mybatisplus.generator.fill.Column;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class MpGenerator {public static void main(String[] args) {
    String url = "jdbc:mysql://localhost:3306/hzit-manager?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai";
    String username = "root";
    String password = "z1b2c3e4";
    FastAutoGenerator.create(url, username, password)
            // 全局配置
            .globalConfig((scanner, builder) -> builder.author(scanner.apply("请输入作者名称？"))
                    .outputDir(scanner.apply("请输入输出路径？"))
            )
            // 包配置
            .packageConfig((scanner, builder) -> builder.parent(scanner.apply("请输入包名？")))
            // 策略配置
            .strategyConfig((scanner, builder) -> builder
                    .addInclude(getTables(scanner.apply("请输入表名，多个英文逗号分隔？所有输入 all")))
                    .addTablePrefix("tb_")     // 去掉表前缀
                    .entityBuilder()
                    .enableLombok()

                    .addTableFills(
                            new Column("create_time", FieldFill.INSERT)
                    )
                    .build())

            .templateEngine(new FreemarkerTemplateEngine())
            .execute();
}


    protected static List<String> getTables(String tables) {
        return "all".equals(tables) ? Collections.emptyList() : Arrays.asList(tables.split(","));
    }
}
